class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}

class Solution {
    //创建两个节点来指向头结点和上一个节点
    TreeNode head = null;
    TreeNode prev = null;
    public TreeNode Convert(TreeNode pRootOfTree) {
        //递归到左边最小值就返回
        if(pRootOfTree == null){
            return null;
        }
        //往左边递归，找最小值
        Convert(pRootOfTree.left);
        //左边递归完毕，说明已经找到最小值
        if (prev == null){
            head = pRootOfTree;
            prev = pRootOfTree;
        }else {
            //和上一个节点建立联系,并把prev置为当前节点
            prev.right = pRootOfTree;
            pRootOfTree.left = prev;
            prev = pRootOfTree;

        }
        Convert(pRootOfTree.right);
        //TreeNode cur = pRootOfTree;
        return head;
    }
}
public class Test {

}
